Home:ALL Converter>How to Run WireShark Commands in command line through C#

How to Run WireShark Commands in command line through C#

Ask Time:2020-03-11T22:29:28         Author:Cherylaksh

Json Formatter

I want to convert .pcapng files to .csv files using the below commands:

     > cd C:\Program Files\Wireshark
     > tshark -r output.pcapng -T fields -e frame.number -e eth.src -e eth.dst -e frame.len -e frame.time -e frame.time_relative -e data -E header=y -E separator=, > output.csv

In C#, I used the following code.

        string command = @"cd C:\Program Files\Wireshark & tshark -r output.pcapng -T fields -e frame.number -e eth.src -e eth.dst -e frame.len -e frame.time -e frame.time_relative -e data -E header=y -E separator=, > output.csv";
        System.Diagnostics.Process process = new System.Diagnostics.Process();
        System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
        startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
        startInfo.FileName = "CMD.exe";
        startInfo.Arguments = command;
        startInfo.Verb = "runas";
        process.StartInfo = startInfo;
        process.Start();
        process.WaitForExit();

This doesnt seem to be working.

Author:Cherylaksh,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60638402/how-to-run-wireshark-commands-in-command-line-through-c-sharp
Neil :

Check that path:\n\nstring command = @\"cd C:\\ProgramFiles\\Wireshark & tshark -r output.pcapng -T fields -e frame.number -e eth.src -e eth.dst -e frame.len -e frame.time -e frame.time_relative -e data -E header=y -E separator=, > output.csv\";\n\nOn my machine, Program Files has a space between the two words, and Wireshark & tshark is suspicious too. Ampersand (especially when using shells) is interpreted differently.",
2020-03-11T14:53:49
yy